package com.tgy.JUC.lock8;

import java.util.concurrent.TimeUnit;

/***
 * @ClassName: Test1
 * @Description: 关于锁的八个问题
 * @Auther: 送你一块二向箔
 * @Date: 10:45 2022/3/11
 * @version : V1.0
 */
public class Test1 {
    public static void main(String[] args) {
        Phone phone = new Phone();
        new Thread(()->{phone.sendSms();},"A").start();
        new Thread(()->{phone.call();},"B").start();

    }
}
class Phone{

    //synchronized 锁的对象是方法的调用者
    //两个方法用的同一个锁，谁先拿到谁执行
    public synchronized void sendSms(){
        try {
            TimeUnit.SECONDS.sleep(4L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("sendSms");
    }
    public synchronized void call(){

        System.out.println("call");
    }

}
